package controller.states;

import model.GameModel;
import model.entities.IEntity;
import controller.GameController;
import controller.IPlayerAction;
import controller.IState;
import controller.actions.BinAction;
import controller.actions.EntityAction;
import controller.actions.EntityClickedAction;

/**
 * 
 * This state is active when an entity is to be placed
 *
 */
public class PlaceEntityState implements IState {
	
	private GameController controller;
	private IEntity entity;
	
	public PlaceEntityState(GameController controller, IEntity entity) {
		this.controller = controller;
		this.entity = entity; 
	}

	@Override
	public void handleAction(IPlayerAction playerAction) {	}

	@Override
	public void handleEntityClickedAction(EntityClickedAction action) {	
		GameModel model = controller.getModel();
		boolean success = entity.addSelfToGameBoard(model.getGameBoard(), action.getCell());
		if (!success)
			return;
		controller.getView().resetCursor();
		controller.getView().setGridOn(false);
		controller.getView().laserAnimationOn(true);
		controller.setState(new InGameState(controller));
		model.setDirty();
	}

	@Override
	public void handleEntityDraggedAction(EntityAction action) { }

	@Override
	public void handleEntityReleasedAction(EntityAction action) { }

	@Override
	public void handleBinClicked(BinAction action) {
		GameModel model = controller.getModel();
		
		entity.addSelfToBin(model.getBin());
		
		controller.getView().resetCursor();
		controller.getView().setGridOn(false);
		controller.getView().laserAnimationOn(true);
		controller.setState(new InGameState(controller));
		model.setDirty();
	}

	@Override
	public void handleBinDraggedAction(BinAction action) {}

	@Override
	public void handleLevelLoadAction(String levelName) {}


}
